package com.yuntian.controller.user;

import com.yuntian.Dto.NotePageQueryDto;
import com.yuntian.entity.Note;
import com.yuntian.result.PageResult;
import com.yuntian.result.Result;
import com.yuntian.service.NoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/notes")
public class NoteController {

    @Autowired
    private NoteService noteService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public Result<PageResult> list(NotePageQueryDto notePageQueryDto) {
            PageResult notes = noteService.list(notePageQueryDto);
            return Result.success(notes);
    }

    /**
     * 新增笔记
     */
    @PostMapping("/add")
    public Result<Void> insertNote(@RequestBody Note note) {
            noteService.insertNote(note);
            return Result.success();
    }

    /**
     * 修改笔记
     */
    @PutMapping("/update")
    public Result<Void> updateNote(@RequestBody Note note) {
            noteService.updateNote(note);
            return Result.success();
    }
    /**
     * 删除笔记
     */
    @DeleteMapping("/delete/{noteId}")
    public Result<Void> deleteNote(@PathVariable Integer noteId) {
            noteService.deleteNote(noteId);
            return Result.success();
    }
}
